const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;

    @property
    text: string = 'hello';

    @property(cc.Node)
    player_head_node: cc.Node = null;

    @property(cc.Node)
    player_body_node: cc.Node = null;

    @property(cc.Prefab)
    player_body_prefab: cc.Prefab = null;
    // LIFE-CYCLE CALLBACKS:

    //身体对象池
    private _player_body_pool:any;

    onLoad () {
        this.node.on("body_add",this.body_add.bind(this));
        this.node.on("body_minus",this.body_minus.bind(this));

        //身体 对象池 初始化
        this._player_body_pool = new cc.NodePool(); 
        let init_body_count = 10;
        for (let i = 0; i < init_body_count; ++i) {
            let body = cc.instantiate(this.player_body_prefab); // 创建节点
            this._player_body_pool.put(body); // 通过 put 接口放入对象池
        }
    }

    start () {

    }

    body_add(){
        //先将头抬起来
        console.log('this.player_head_node.children[0]:',this.player_head_node.children[0]);
        this.player_head_node.children[0].y = this.player_head_node.children[0].y + 100;
       
        
    }

    body_minus(){

    }

    // update (dt) {}
}
